// pages/home/home.js
//获取应用实例
const app = getApp();
import { _get_article_list } from '../../utils/qiaofinn'
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    articles: {},   // 内容数据
    next_page: null,
    // 
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://qiaofinn-1253627477.cos.ap-chengdu.myqcloud.com/qiaofinn/banners/9.png'
    }, {
      id: 1,
      type: 'image',
      url: 'https://qiaofinn-1253627477.cos.ap-chengdu.myqcloud.com/qiaofinn/banners/02.jpg',
    }, {
      id: 2,
      type: 'image',
      url: 'https://qiaofinn-1253627477.cos.ap-chengdu.myqcloud.com/qiaofinn/banners/05.jpg'
    },{
      id: 3,
      type: 'image',
      url: 'https://qiaofinn-1253627477.cos.ap-chengdu.myqcloud.com/qiaofinn/banners/01.jpg'
    },],
    homeNavList: [{
      icon: 'icon-fangjiajisuanqi ',
      color: 'yellow',
      name: '装修预算',
      path: './dec_budget/dec_budget'
    }, {
      icon: 'icon-shu',
      color: 'orange',
      badge: 1,
      name: '装修大全',
      path: './decorate/decorate'
    },
    // {
    //   icon: 'icon-fuwuerji',
    //   color: 'yellow',
    //   badge: 0,
    //   name: '工人信息',
    //   path:'./worker/worker'
    // },
    {
      icon: 'icon-liucheng',
      color: 'olive',
      badge: 22,
      name: '装修流程',
      path: './decorate_process/decorate_process'
    },
      // {
      //   icon: 'icon-youhuiquan',
      //   color: 'olive',
      //   badge: 22,
      //   name: '领取优惠券',
      //   path:'./coupon/coupon'
      // },
      // {
      //   icon: 'icon-fenxiang1',
      //   color: 'olive',
      //   badge: 22,
      //   name: '分享有礼',
      //   path:'./share/share'
      // }
    ],
  },

  // 网格跳转
  homeGridNavTap(res) {
    var path = res.currentTarget.dataset.path
    wx.navigateTo({
      url: path,
    })
  },
  // 文章详情
  tohomeDetailTap(res) {
    wx.navigateTo({
      url: './detail/detail?articleId=' + res.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _get_article_list({}, res => {
      this.setData({
        articles: res.data.dataList,
        next_page: res.data.next
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.next_page) {
      _get_article_list({ currentPage: this.data.next_page }, res => {
        let articles = this.data.articles
        this.setData({
          articles: articles.concat(res.data.dataList),
          next_page: res.data.next
        })
      })
    } else {
      wx.showToast({
        title: '没有更多的数据',
        icon: 'none',
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})